/**
 * Created by Xiaoming on 2017/8/29.
 */

angular.module('module.auth', [
        'service.auth',
        'service.ucauth',
        'service.ucuser',
        'service.wxauth'
])
    .config(['$stateProvider',
        function ($stateProvider) {
            $stateProvider
                .state('login', {
                    url: '/login?backurl',
                    resolve: {
                        userid: judgeLogin
                    },
                    templateUrl: auth_viewurl + '/login.html',
                    controller: 'LoginController',
                    controllerAs: 'vm'
                })
                .state('register', {
                    url: '/register',
                    resolve: {
                        userid: judgeLogin
                    },
                    templateUrl: auth_viewurl + '/register.html',
                    controller: 'RegisterController',
                    controllerAs: 'vm'
                })
                .state('repassword', {
                    url: '/repassword',
                    resolve: {
                        userid: judgeLogin
                    },
                    templateUrl: auth_viewurl + '/repassword.html',
                    controller: 'RepasswordController',
                    controllerAs: 'vm'
                })
                .state('settings', {
                    url: '/settings',
                    resolve: {
                        user: getUser,
                    },
                    templateUrl: auth_viewurl + '/settings.html',
                    controller: 'SettingsController',
                    controllerAs: 'vm'
                })
            ;
        }]);
//判断用户是否已经登录
judgeLogin.$inject = ['AuthUserService'];
function judgeLogin(AuthUserService) {
    var userId = AuthUserService.getUserByIdCookies();
    if (userId != null) {
        return window.history.back();
    }
}
//获取用户信息
getUser.$inject = ['AuthUserService', 'AuthService'];
function getUser(AuthUserService, AuthService) {
    var userId = AuthUserService.getUserByIdCookies();
    return AuthService.getuser(userId).$promise;
}